// xc_lshop/wholesale/index/index.js
var actbill = require('../model/pro_contents')

Page({
  mixins: [require('../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    scrollleft:0,
    nav:[],
  },
  xcloaddata: function (options, config) {
    if(config.wholesale && config.wholesale.home){
      this.setData({
        wholesalehome: config.wholesale.home
      })
    }else{
      this.error("批发首页未配置")
    }

    if (config.prothem && config.prothem.prolist) {
      var proconfig = config.prothem.prolist.proconfig;
      var customStyle = config.prothem.prolist.customStyle;
     

      var popconfig = config.prothem.popup.proconfig;
      var popCustomStyle = config.prothem.popup.customStyle;
      this.setData({
        proconfig: proconfig,
        navtype: proconfig.left.navmode,
        customStyle: customStyle,
        popconfig: popconfig,
        popCustomStyle: popCustomStyle
      })
    }
    this.setData({
      config: config
    })
    var that=this
    that.getpagelist(that,1)
  },
  getpagelist(that, rest, strwhere) {
    if (rest == 1) {
      if (!strwhere) {
        strwhere = {};
      }

      strwhere["status"] = 1;
      strwhere['presaletime']=1;
      that.setData({
        modellist: []
      });
    }
    actbill.offset(that, rest, strwhere).then(function (result) {
      var updatemdoel = {};

      if ((result["code"] == "over" && result["obj"]) || result["code"] == "loadmore") {

        for (var a in result["obj"]["modellist"]) {
          if (result["obj"]["modellist"][a]) {
            result["obj"]["modellist"][a]["snapshot"] = JSON.parse(result["obj"]["modellist"][a]["snapshot"])
          }
        }
        if (rest == 1) {
          updatemdoel["modellist"] = result["obj"]["modellist"];
        } else {
          if (result["obj"]["modellist"].length > 0) {
            updatemdoel["modellist"] = that.data.modellist.concat(result["obj"]["modellist"]);
          }
        }
      }
      wx.stopPullDownRefresh();
      that.setData(updatemdoel);


    });
  },
  buy: function (ev) {
    var that = this
    var dataset = ev.currentTarget.dataset
    var item = dataset.item



    // 1加购 2立即购买 3两种
    // console.log(item)
   
    
    // var dataset = ev.detail.dataset;

    var app = getApp();
    var that = this;
    app.xc_sys_config.authop.oppower("login").then(function (res) {
      if (res.status == 1) {
        var obj=res.obj;
        var wsgrade=obj.memberinfo.wsgrade;
        var option={}
        option['wsgrade']=wsgrade
        actbill.showattrchose(that, item.id, null, 3,option)


        // actbill.showattrchose(that, that.data.id, that.data.selected, ev.currentTarget.dataset.op, option)
      }
    })

  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this
    this.getpagelist(that, -1)

  },
})